<?php
abstract class AbstractParseMessage {
    /**
     * @var Parser
     */
    protected $parser = null;
    protected $stats = array();
    
    protected $name = null;

    protected function addComment($nb) {
        if( null !== $this->name ) {
            $this->incStats('comment', $nb);
        }
    }
    
    protected function addLines() {
        if( null !== $this->name ) {
            $this->incStats('linesCount', 1);
        }
    }
    
    protected function setStatValue($name, $value) {
        $this->stats[$name] = $value;
    }
    
    protected function addStatInArray($name, $value, $key = null) {
        if( ! isset($this->stats[$name])) $this->stats[$name] = array();
        if( null === $key ) $this->stats[$name][] = $value;
        else $this->stats[$name][$key] = $value;
    }
    
    protected function getStatValue($name) {
        return isset($this->stats[$name])?$this->stats[$name]:null;
    }
    
    protected function getStatArray($name) {
        return isset($this->stats[$name])?$this->stats[$name]:array();
    }
    
    protected function incStats($name, $value) {
        if( ! isset( $this->stats[$name] ) ) {
            $this->stats[$name] = 0;
        }
        $this->stats[$name] += $value;
         
    }
    
    public function __construct($parser) {
        $this->parser = $parser;
    }
    
    public function getStats() {
        return $this->stats;
    }
    
    public function reset() {
        $this->name = null;
        $this->stats = array();
        $this->setStatValue('linesCount', 0);
        $this->setStatValue('cyclo', 1);
    } 
    
    protected function sendMessage($title, $message) {
        $this->parser->sendMessage($title, $message);
    }
    
    abstract public function reveive($title, $message);
     
}